<style>
</style>
<script type="text/template" id="territory-manage-template">
    <div class="territory-manage">
        <div class="head">
            <div class="search">
                <input type="" name="" class="search-input">
            </div>
            <div class="btn-area">
                <a href="javascript:;" class="add" title="Add" id="add-territory"></a>
                <a href="javascript:;" class="save" title="Save"></a>
            </div>
        </div>
        <div class="territory-list">
            <div class="items" data-id="">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
            <div class="items">周一</div>
        </div>
        <div class="footer">
            <span class="yes-btn" id="yes-btn">确定</span>
        </div>
    </div>
</script>


<script>
    {
        $('#territory-manage').click( function () {
            let source=$('#territory-manage-template').html();
            let template = Handlebars.compile(source);
            let html = template({});
            $.Pop(html,{Close:true,CloseBtn:true,Title:'Territory Manage'});
            $('#add-territory').click( function () {
                let html=`
                  <input id="add-territory-input" style="height: 30px;" placeholder="New Territory" />
                  <a style="text-decoration: none;padding: 5px 8px;background: #1f7fe4d6;color: white;" id="save-territory-value">保存</a>

            `;
                $.Pop(html,{CloseBtn:true,Title:'Add Territory',Btn:{yes:{vla:"确定"}}})
            });


        });
        //监听Add Territory页面保存按钮
        $(document).on('click','#save-territory-value',function () {
            let territory = $('#add-territory-input').val();
            if(!territory){
                $.Pro('请输入 Territory');
                return false;
            }

            //填充到列表
            new Promise( function (reslove , reject) {
                
            })
            //生成唯一group_id
            let group_id = md5(new Date().toDateString()+Math.random());

            $('.territory-list').prepend('<div class="items" data-id="'+territory+'">'+territory+'</div>');

            //关闭提示框
            $(this).parent().prev().find('i').trigger('click');
        });

        //
        $(document).on('click','.territory-list .items',function () {
            $(this).addClass('selected').siblings().removeClass('selected');
        });

        //选择Territory
        $(document).on('click','#yes-btn',function () {
            let obj = $('.territory-list').find('.selected');
           // CONFIG.territoryName={};
            $(this).parent().prev().find('i').trigger('click');

        });


    }
</script>

